package com.baidu.controller.servlet;
import com.baidu.Service.StudentService;
import com.baidu.Service.impl.StudentServiceImpl;
import com.baidu.domain.Student;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;

public class FindServlet extends HttpServlet {
     StudentService ss = new StudentServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取学生信息
        ArrayList<Student> list =  ss.findStudent();
        //向session域中添加list集合
        HttpSession session = req.getSession();
        session.setAttribute("students",list);
        //响应重定向到前端页面
        //获取虚拟目录的名称
        String path = req.getContextPath();
        resp.sendRedirect(path+"/listStudent.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
